<?php 
/**
*每个店的统计数据
*/

//地址栏传来的地址,根据此地址
$address=$_REQUEST['address'];

date_default_timezone_set('Asia/Shanghai');
//初始化数据
require('./include/init.php');

//连接数据库
$mysql=mysql::getIns();
// $data=$mysql->getAll("select * from alldev");
// print_r($data);
// print_r($data);
//统计当前在线人数    (在线人数为当前时间的十分钟之前到现在的人数)










$maxtime=time();
$mintime=$maxtime-10*60;
// echo $maxtime . '<br />';
// echo $mintime;
$sql="select count(*) from alldev where timestamp > $mintime and timestamp < $maxtime and shop='". $address ."'";
$allnow=$mysql->getOne($sql);
// echo $allnow;
// print_r($allnow);
// exit;


//统计当天累计人数数
$t = time();
$start = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
$end = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
$sql="select count(*) from alldev where timestamp > $start and timestamp < $end and shop='" . $address . "'";
$allday=$mysql->getOne($sql);
// echo $allday;
// exit;
//首次今天首次进店人数,通过字段visittimes为1来进行判断
$sql="select count(*) from alldev where visittimes=1 and timestamp > $mintime and timestamp < $maxtime and shop='".$address ."'";
$first=$mysql->getOne($sql);

//统计当前销售区
$sql="select count(*) from alldev where timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."' and area in ('展厅区','销售区','精品区')";
$sale=$mysql->getOne($sql);
// echo $sale;
// print_r($sale);
// exit;

//统计当前售后区
$service=$allnow-$sale;


//今天多次进店人数
$sql="select count(*) from alldev where visittimes <> 1 and timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."'";
$second=$mysql->getOne($sql);

//统计登陆人数
$sql="select count(*) from alldev where isOL=1 and timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."'";
$login=$mysql->getOne($sql);
// echo $login;

//统计未登陆人数
$sql="select count(*) from alldev where isOL=2 and timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."'";
$nolog=$mysql->getOne($sql);
// echo $nolog;

//统计历史进店人数
$sql="select count(*) from alldev where shop='". $address ."'";
$history=$mysql->getOne($sql);
$data=include('./include/history.inc.php');
// print_r($data);
$b=$data["$address"];
$history+=$b;
// exit;
require(ROOT . 'view/iwocar5/4S_GManager.html');
// echo $history;
 ?>